import urllib.request
import urllib.parse

url = 'https://fanyi.baidu.com/sug'

headers = {
    "User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0',
}

data = {
    'kw': 'spider'
}

# post请求的参数，一定要进行编码

data = urllib.parse.urlencode(data).encode('utf-8')

# post请求的参数
request = urllib.request.Request(url=url, data=data, headers=headers)

# 模拟浏览器发送请求
response = urllib.request.urlopen(request)
#编码之后一定要用encode方法
content = response.read().decode('utf-8')

import json

obj=json.loads(content)

print(obj)
